package com.h2cloud.reflection.Field;

/**
 * @Package: com.h2cloud.reflection.Field
 * @ClassName: Main
 * @Author: h2cloud
 * @CreateTime: 2023/7/20 11:58 下午
 * @Description:
 */

import java.lang.reflect.Field;

import java.lang.reflect.Field;

public class Main {
	public static void main(String[] args) throws IllegalAccessException {
		System.out.println("Object.class.getDeclaredFields().length = " + Object.class.getDeclaredFields().length);
		ChildClass child = new ChildClass();

		Field[] fields = ChildClass.class.getDeclaredFields();
		for (Field field : fields) {
			field.setAccessible(true); // 设置私有字段可访问
			System.out.println("Field name: " + field.getName() + ", Value: " + field.get(child));
		}
	}
}

class GrandparentClass {
	private int grandparentPrivateField = 1;
	protected int grandparentProtectedField = 2;
	public int grandparentPublicField = 3;
}

class ParentClass extends GrandparentClass {
	private int parentPrivateField = 4;
	protected int parentProtectedField = 5;
	public int parentPublicField = 6;
}

class ChildClass extends ParentClass {
	private int childPrivateField = 7;
	protected int childProtectedField = 8;
	public int childPublicField = 9;
}
